home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programmer Power Tools
/
Programmer Power Tools.iso
/
pcresrc
/
pcr8905.arc
/
UITEST.C
< prev
next >
Wrap
Text File
|
1989-02-07
|
4KB
|
130 lines
/* This program will test the DOS shell core program */
/* Written for Microsoft C, Quick C, and Turbo C */
#include <stdio.h>
#include <stdlib.h>
#include <dos.h>
#include <conio.h>
#define MSC 1 /* Set to 0 for Turbo C /*
#if MSC /* Smooth differences between compilers */
#pragma pack(1)
#define MAKE_FP(ptr,seg,off) {FP_SEG(ptr) = seg; FP_OFF(ptr) = off;}
#else
#define MAKE_FP(ptr,seg,off) {ptr = MK_FP(seg,off);}
#endif
int far *IACA; /* Inter-Application Communication Area */
char far *exec_tail; /* Command tail buffer */
char far *exec_path; /* Program name buffer */
char far *ui_buf; /* Buffer for status data between runs */
int far *exec_code; /* Buffer for command code */
unsigned seg_addr, off_addr;
int far *exec_count; /* We'll count the number of times this */
/* program is invoked */
#define EXIT 0 /* List of command codes */
#define RESET 1
#define CMD_EXEC 2
#define DIR_CMD 3
#define SHELL 4
#define ENVR 5
#define PAUSE 0x80
void do_exit(void); /* Function prototypes */
void do_cmd_exec(void);
void do_dir_exec(void);
void do_shell(void);
void ch_dir(void);
void change_env(char *s);
void main(void) /* Execution starts here */
{
int ch;
char *s;
MAKE_FP(IACA,0,0x4f0); /* Address of IACA */
seg_addr = *IACA++; /* Get segment of all buffers */
/* Add offsets of each buffer: */
MAKE_FP(exec_path, seg_addr, *IACA++);
MAKE_FP(exec_tail, seg_addr, *IACA++);
MAKE_FP(ui_buf, seg_addr, *IACA++);
MAKE_FP(exec_code, seg_addr, *IACA);
exec_count = (int far *)ui_buf;
puts("Current environment: ");
for(ch = 0;*environ[ch];ch++)
printf("%s\n",environ[ch]);
puts("\n\n\n Shell Core Tester");
printf("\t\t%d executions in this session\n",(*exec_count)++);
puts("");
puts("\t1. Exit the program");
puts("\t2. Execute via Command.Com");
puts("\t3. Execute directly");
puts("\t4. Shell to Command.Com");
puts("\t5. SET XYZ=1 2 3");
puts("\t6. SET XYZ=4 5 6");
puts("\t7. SET XYZ=");
printf("\t Your choice ==>");
do {
ch = getch();
} while (ch < '1' || ch > '7');
switch(ch) {
case '1': do_exit(); break;
case '2': do_cmd_exec(); break;
case '3': do_dir_exec(); break;
case '4': do_shell(); break;
case '5': s = "XYZ=1 2 3";
change_env(s); break;
case '6': s = "XYZ=4 5 6";
change_env(s); break;
case '7': s = "XYZ=";
change_env(s); break;
}
}
void do_exit(void)
{
*exec_code = EXIT;
exit(0);
}
void do_cmd_exec()
{
char *cp;
cp = "DIR";
while(*exec_tail++ = *cp++);
*exec_code = (CMD_EXEC | PAUSE);
exit(0);
}
void do_dir_exec(void)
{
char *cp;
cp = "C:\\BIN\\PMAP.EXE"; /* Put name of any utility here */
while (*exec_path++ = *cp++);
*exec_code = DIR_CMD;
exit(0);
}
void do_shell(void)
{
*exec_code = (SHELL | PAUSE);
exit(0);
}
void change_env(char *s)
{
while(*exec_tail++ = *s++);
*exec_code = ENVR;
exit(0);
}